package com.jerei.plugin.control;

import com.jerei.plugin.entity.WcmCommonAdminuser;
import com.jerei.plugin.service.IWcmCommonAdminuserService;
import com.jerei.utils.UtilsCommon;
import com.jerei.utils.UtilsCondition;
import com.jerei.utils.spring.PageBean;
import com.jerei.web.plugin.controller.PluginController;
import com.jerei.web.utils.UtilsUI;
import com.jerei.web.utils.UtilsWeb;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import ro.fortsoft.pf4j.Extension;

/**
 * Created by sunfeihu on 2016/10/21.
 */
@Extension
public class WcmCommonAdminuserControl extends PluginController {

    //业务逻辑层
    @Autowired
    private IWcmCommonAdminuserService iWcmCommonAdminuserService;

    /**
     * 保存和修改数据
     *
     * @return 保存结果
     */
    @RequiresPermissions({"common-adminuser:save:*", "common-adminuser:update:*"})
    public String save() {
        WcmCommonAdminuser entity = this.wrapper(WcmCommonAdminuser.class);
        if (entity.getId() != null && entity.getId() > 0L) {
            iWcmCommonAdminuserService.update(entity);
        } else {
            iWcmCommonAdminuserService.save(entity);
        }
        return UtilsUI.ok();
    }

    /**
     * 数据删除
     *
     * @return 删除结果
     */
    @RequiresPermissions("common-adminuser:remove:*")
    public String delete() {
        String[] ids = this.getRequest().getParameterValues("ids");
        if (null != ids && ids.length > 0) {
            for (int i = 0; i < ids.length; i++) {
                iWcmCommonAdminuserService.delete(UtilsCommon.getLong(ids[i]));
            }
        }
        return UtilsUI.fail();
    }

    /**
     * 进入编辑页
     *
     * @return 编辑页的视图路径
     */
    @RequiresPermissions({"common-adminuser:save:*", "common-adminuser:update:*", "common-adminuser:view:*"})
    public void edit() {
        Long id = UtilsWeb.getLong(this.getRequest(), "id");
        WcmCommonAdminuser entity = iWcmCommonAdminuserService.find(id);
        this.getModel().addAttribute("obj", entity);
    }

    @RequiresPermissions("common-adminuser:view:*")
    public String page() {
        Integer nowPage = UtilsWeb.getInteger(this.getRequest(), "page");
        Integer pageSize = UtilsWeb.getInteger(this.getRequest(), "rows");
        PageBean<WcmCommonAdminuser> pageBean = iWcmCommonAdminuserService.page(nowPage, pageSize, UtilsCondition.getConditionEntity(this.getRequest().getParameterMap()));
        return UtilsUI.datagrid(pageBean);
    }

    /**
     * 开发者管理员
     *
     * @return
     */
    @RequiresPermissions("common-adminuser:view")
    public String pageDev() {
        Integer nowPage = UtilsWeb.getInteger(this.getRequest(), "page");
        Integer pageSize = UtilsWeb.getInteger(this.getRequest(), "rows");
        PageBean<WcmCommonAdminuser> pageBean = iWcmCommonAdminuserService.pageDev(nowPage, pageSize);
        return UtilsUI.datagrid(pageBean);
    }

}